/***************************************************************************
 *         tty_test.c
 *
 * Thu May 24 11:22:27 2007
 * Copyright  2007  kf701
 * Email <kf701.ye AT gmail.com>
 *****************************************************************************/


#include <errno.h>
#include <sys/types.h>
#include <fcntl.h>

#include "factory.h"

int main(int argc, char **argv)
{
	int nread, fd;
	char buff[512];

	if( argc == 2 )
		fd = open( argv[1], O_RDWR );
	else
		fd = open( "/dev/ttyS0", O_RDWR ); //| O_NOCTTY | O_NDELAY
	if (-1 == fd)
	{
		perror("Can't Open Serial Port");
		return -1;
	}

	set_speed(fd,115200);
	if (set_parity(fd,8,1,'N') == false)
	{
		printf("Set Parity Error\n");
		exit (0);
	}

	while (1)
	{
		while((nread = readline2(fd, buff, 512))>0)
		{
			printf( "%s", buff);
		}
	}

	close(fd);
	exit (0);
}

